﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace System.Text.CP866U.Test
{
	[TestClass]
	public sealed class UnitTest
	{
		private readonly byte[] _bytes = new byte[] { 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9 };
		private readonly char[] _chars = new char[] {'Ё', 'ё', 'Ґ', 'ґ', 'Є', 'є', 'І', 'і', 'Ї', 'ї'};

		private readonly string _text = "Музика без'язика людей збирає. За ґратами і солома їдома.";
		private readonly byte[] _textBytes = new byte[] 
		{
			0x008c, 0x00e3, 0x00a7, 0x00a8, 0x00aa, 0x00a0, 0x0020, 0x00a1, 0x00a5, 0x00a7, 0x0027, 0x00ef, 0x00a7, 0x00a8, 0x00aa, 0x00a0,
			0x0020, 0x00ab, 0x00ee, 0x00a4, 0x00a5, 0x00a9, 0x0020, 0x00a7, 0x00a1, 0x00a8, 0x00e0, 0x00a0, 0x00f5, 0x002e, 0x0020, 0x0087,
			0x00a0, 0x0020, 0x00f3, 0x00e0, 0x00a0, 0x00e2, 0x00a0, 0x00ac, 0x00a8, 0x0020, 0x00f7, 0x0020, 0x00e1, 0x00ae, 0x00ab, 0x00ae,
			0x00ac, 0x00a0, 0x0020, 0x00f9, 0x00a4, 0x00ae, 0x00ac, 0x00a0, 0x002e
		};

		[TestMethod]
		public void EncodeChars1()
		{
			var result = new CP866UEncoding().GetBytes(_chars);

			CollectionAssert.AreEqual(_bytes, result);
		}

		[TestMethod]
		public void DecodeBytes1()
		{
			var result = new CP866UEncoding().GetChars(_bytes);

			CollectionAssert.AreEqual(_chars, result);
		}

		[TestMethod]
		public void EncodeChars2()
		{
			var result = new CP866UEncoding().GetBytes(_text.ToCharArray());

			CollectionAssert.AreEqual(_textBytes, result);
		}

		[TestMethod]
		public void DecodeBytes2()
		{
			var result = new CP866UEncoding().GetChars(_textBytes);

			CollectionAssert.AreEqual(_text.ToCharArray(), result);
		}
	}
}